Skip to content

Conversation

Zalathar
Copy link
Contributor


This PR dismantles the somewhat complicated LLVMRustDIBuilderCreateStaticVariable function, and replaces it with equivalent calls to LLVMDIBuilderCreateGlobalVariableExpression and LLVMGlobalSetMetadata.

A key difference is that the new code does not replicate the attempted downcast of InitVal. As far as I can tell, those downcasts were actually dead, because llvm::ConstantInt and llvm::ConstantFP are not subclasses of llvm::GlobalVariable. I tried replacing those code paths with fatal errors, and was unable to induce failure in any of the relevant test suites I ran.

I have also confirmed that if the calls to create_static_variable are commented out, debuginfo tests will fail, demonstrating some amount of relevant test coverage.

The new DIBuilder methods have been added via an extension trait, not as inherent methods, to avoid impeding #142897.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Note that the code in `LLVMRustDIBuilderCreateStaticVariable` that tried to
downcast `InitVal` appears to have been dead, because `llvm::ConstantInt` and
`llvm::ConstantFP` are not subclasses of `llvm::GlobalVariable`.
@nnethercote
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 13, 2025

📌 Commit 1081d98 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 13, 2025
cg_llvm: Use `LLVMDIBuilderCreateGlobalVariableExpression`

- Part of rust-lang#134001
- Follow-up to rust-lang#146763

---

This PR dismantles the somewhat complicated `LLVMRustDIBuilderCreateStaticVariable` function, and replaces it with equivalent calls to `LLVMDIBuilderCreateGlobalVariableExpression` and `LLVMGlobalSetMetadata`.

A key difference is that the new code does not replicate the attempted downcast of `InitVal`. As far as I can tell, those downcasts were actually dead, because `llvm::ConstantInt` and `llvm::ConstantFP` are not subclasses of `llvm::GlobalVariable`. I tried replacing those code paths with fatal errors, and was unable to induce failure in any of the relevant test suites I ran.

I have also confirmed that if the calls to `create_static_variable` are commented out, debuginfo tests will fail, demonstrating some amount of relevant test coverage.

The new `DIBuilder` methods have been added via an extension trait, not as inherent methods, to avoid impeding rust-lang#142897.
bors added a commit that referenced this pull request Oct 13, 2025
Rollup of 6 pull requests

Successful merges:

 - #147514 (repr_transparent_external_private_fields: normalize types during traversal)
 - #147605 (Add doc links between `{integer}::from_str_radix` and `from_str`)
 - #147608 (cg_llvm: Use `LLVMDIBuilderCreateGlobalVariableExpression`)
 - #147623 (Clear `ChunkedBitSet` without reallocating)
 - #147625 (Add a warning when running tests with the GCC backend and debug assertions are enabled)
 - #147626 (Generalize configuring LLD as the default linker in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3938f42 into rust-lang:master Oct 13, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 13, 2025
rust-timer added a commit that referenced this pull request Oct 13, 2025
Rollup merge of #147608 - Zalathar:debuginfo, r=nnethercote

cg_llvm: Use `LLVMDIBuilderCreateGlobalVariableExpression`

- Part of #134001
- Follow-up to #146763

---

This PR dismantles the somewhat complicated `LLVMRustDIBuilderCreateStaticVariable` function, and replaces it with equivalent calls to `LLVMDIBuilderCreateGlobalVariableExpression` and `LLVMGlobalSetMetadata`.

A key difference is that the new code does not replicate the attempted downcast of `InitVal`. As far as I can tell, those downcasts were actually dead, because `llvm::ConstantInt` and `llvm::ConstantFP` are not subclasses of `llvm::GlobalVariable`. I tried replacing those code paths with fatal errors, and was unable to induce failure in any of the relevant test suites I ran.

I have also confirmed that if the calls to `create_static_variable` are commented out, debuginfo tests will fail, demonstrating some amount of relevant test coverage.

The new `DIBuilder` methods have been added via an extension trait, not as inherent methods, to avoid impeding #142897.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants